package com.ccl.iot.huiju;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class BaseFragment extends Fragment {

//    protected MainActivity mActivity;

    protected Context mContext;

    protected boolean isHidden = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
        super.onViewStateRestored(savedInstanceState);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mContext = context;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        View view = setContentView(inflater,container);

        initView(view);

        initListener();

        initData();

        return view;
    }




    @Override
    public void onResume() {
        super.onResume();
        if (!isHidden){
            Log.e("PageFragment", "onResume--"+getClass().getSimpleName());
            onShow();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        if (!isHidden){
            Log.e("PageFragment", "onPause--"+getClass().getSimpleName());
            onHide();
        }
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        this.isHidden = hidden;
        if (!hidden) {
            Log.e("PageFragment", "onHiddenChanged---onShow--"+getClass().getSimpleName());
            onShow();
        } else {
            Log.e("PageFragment", "onHiddenChanged---onHide--"+getClass().getSimpleName());
            onHide();
        }
    }



    protected abstract void onShow();
    protected abstract void onHide();

    protected abstract View setContentView(LayoutInflater inflater, ViewGroup container);

    protected abstract void initView(View view);

    protected abstract void initListener();

    protected abstract void initData();


}
